<?php

declare(strict_types=1);

namespace app\admin\controller;

use addons\Builder\facade\Builder;
use app\common\tool\Result;
use think\facade\View;
use addons\Gallery\driver\Gallery;
//该文件为自动生成，请按需修改
class CourseChapter extends Base
{
    //主键，默认为id
    protected string $pk = 'id';

    //主模型
    protected string $model = '\app\common\model\CourseChapter';

    public function index(): string
    {
        $param = $this->request->param();
        if (isset($param['id'])) {
            $map[] = ['course_id', '=', $param['id']];
        }
        $map[] = ['course_id', '<>', 0];
        return Builder::Table()
            ->autoStructure($this->model, $this->pk, 'barDemo,200')
            ->addRightButtons(['edit' => ['size' => '60%'], 'delete'])
            ->addTopButtons([
                'add' => [
                    'size' => '60%',
                    'url' => url('courseChapter/add')->build() . '?id=' . $param['id'],
                ],
                'deleteAll'
            ])
            ->addExtraMap($map)
            ->fetch();
    }

    public function add($tpl = 'course_chapter/edit')
    {
        $param = $this->request->param();
        $qn_token = Gallery::getQnList();
        view::assign(
            [
                'id' => $param['id'],
                'info' => [],
                'qn_token' => $qn_token['token'],
                'qn_url' => $qn_token['url'],
                'domain_url' => $qn_token['domain'],
            ]
        );
        return parent::add($tpl); // TODO: Change the autogenerated stub
    }
    public function edit($id = '', $tpl = 'course_chapter/edit', $info = '')
    {
        $qn_token = Gallery::getQnList();
        $info = $this->model::find($id);
        view::assign(
            [
                'id' => $info['course_id'],
                'qn_token' => $qn_token['token'],
                'qn_url' => $qn_token['url'],
                'domain_url' => $qn_token['domain'],
            ]
        );
        return parent::edit($id, $tpl, $info); // TODO: Change the autogenerated stub
    }
}
